<html class="x-admin-sm">
<head>
<meta charset="UTF-8">
<title>欢迎页面-X-admin2.1</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
<link rel="stylesheet" href="./css/font.css">
<link rel="stylesheet" href="./css/xadmin.css">
<script type="text/javascript"
	src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="./lib/layui/layui.js"
	charset="utf-8"></script>
<script type="text/javascript" src="./js/xadmin.js"></script>
<script type="text/javascript" src="./js/cookie.js"></script>
<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
<!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
	<div class="x-nav">
		<span class="layui-breadcrumb"> <a href="">首页</a> <a href="">演示</a>
			<a> <cite>导航元素</cite></a>
		</span> <a class="layui-btn layui-btn-small"
			style="line-height: 1.6em; margin-top: 3px; float: right"
			href="javascript:location.replace(location.href);" title="刷新"> 
			<i class="layui-icon" style="line-height: 30px"></i></a>
	</div>
	<div class="x-body">
		<div class="layui-row">
			<form class="layui-form layui-col-md12 x-so">
				<input type="text" id="tUCount" placeholder="请输入用户名"
					autocomplete="off" class="layui-input">
				<button class="layui-btn" id="select_btn">
					<i class="layui-icon">&#xe615;</i>
				</button>
			</form>
		</div>
		<xblock> 
        <button class="layui-btn" id="not_audit">已发布</button>
        <button class="layui-btn" id="audit">准备赴约</button>
        <button class="layui-btn" id="success_audit">赴约成功</button>
        <span class="x-right" style="line-height:40px" id="totil"></span>
		</xblock>
		<table class="layui-table x-admin">
			<thead>
				<tr>
					<th>ID</th>
					<th>发布人</th>
					<th>发布时间</th>
					<th>旅游时间</th>
					<th>状态</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody id="td">
			</tbody>
		</table>
		<div class="page"></div>
	</div>
	<script>
		//查询所有用户 
		function get_all_user_info(pn, textName, textValue) {
			var adminUser = localStorage.getItem("adminUser");
			adminUser = JSON.parse(adminUser);
			if (adminUser == null) {
				parent.location.href = 'login.html';
				return false;
			}
			$.ajax({
				url : '/meiyou/showTour',
				type : 'POST',
				data : 'pn=' + pn + "&" + textName + "=" + textValue,
				success : function(data) {
					console.log(data);
					if (data.code == 100) {
						//展示数据 
						show_info(data, textName, textValue);
					} else if (data.code == 200) {
						//账号被挤出 
					} else if (data.code == 300) {
						//登录信息过去请重新登录 
						layer.msg('登录信息过期，请重新登录', {
							icon : 1,
							time : 1000
						//2秒关闭（如果不配置，默认是3秒）
						}, function() {
							parent.location.href = "login.html";
						});
					}
				}
			});
		}

		/*用户-删除*/
		function member_del(cid, obj) {
			layer.confirm('确认要删除吗？', function(index) {
				//发异步删除数据
				var id = $('#delete').attr("deleteId");
				$(obj).parents("tr").remove();
				layer.msg('已删除!', {
					icon : 1,
					time : 1000
				});
				location.reload();
				//发送ajax请求删除数据 
				var adminUser = localStorage.getItem("adminUser");
				adminUser = JSON.parse(adminUser);
				if (adminUser == null) {
					parent.location.href = 'login.html';
					return false;
				}
				$.ajax({
					url : "/meiyou/delTour",
					type : "POST",
					data : "tId=" + cid,
					headers : {
						Accept : "application/json; charset=utf-8",
						headerId : adminUser.aId,
						headerToken : adminUser.token
					},
					success : function(data) {
						if (data.code == 100) {
							location.reload();
						} else if (data.code == 200) {

						} else if (data.code == 300) {
							//登录信息过去请重新登录 
							layer.msg('登录信息过期，请重新登录', {
								icon : 1,
								time : 1000
							//2秒关闭（如果不配置，默认是3秒）
							}, function() {
								parent.location.href = "login.html";
							});
						}
					}
				});
			});
		}

		get_all_user_info(1);
		//用户信息展示
		function show_info(data, textName, textValue) {
			//清空之前的数据
			$('#td').empty();
			//数据信息展示 
			var list = data.extend.pageInfo.list;
			$.each(list,function(i, item) {
								var tr = $('<tr></tr>');
								var td = $('<td></td>');
								var tdtId = $('<td></td>').append(item.tId);
								var tdtUCount = $('<td></td>').append(item.tUCount);
								var tdtTime = $('<td></td>').append(item.tTime);
								var tdtSdate = $('<td></td>').append(item.tSdate);
								var tdtState = $('<td></td>').append(item.tState);
								var endtd = $('<td class="td-manage"></td>');
								var a2 = $('<a title="删除" id="delete" href="javascript:;" deleteId="'+item.tId+'"></a>');
								a2.click(function() {
									member_del(item.tId);
								});
								var li2 = $('<i class="layui-icon">&#xe640;</i>');
								a2.append(li2);
								endtd.append(a2);
								tr.append(tdtId).append(tdtUCount).append(tdtTime).append(tdtSdate).append(tdtState).append(endtd);
								$('#td').append(tr);
							});
			  $('#totil').empty();
	    	  $('#totil').append('共有数据：'+data.extend.pageInfo.total+"条");
			//分页操作
			$('.page').empty();
			var div = $('<div></div>');
			//判断是否是首页 
			var shouyea;
			var shangyiye;
			if (data.extend.pageInfo.pageNum == 1) {
				shouyea = $('<a class="num">首页</a>');
				shangyiye = $('<a class="prev">&lt;&lt;</a>');
			} else {
				shouyea = $('<a class="num" href="">首页</a>');
				shangyiye = $('<a class="prev" href="">&lt;&lt;</a>');
				shouyea.click(function() {
					get_all_user_info(1, textName, textValue);
					return false;
				});
				shangyiye.click(function() {
					get_all_user_info(data.extend.pageInfo.pageNum - 1,
							textName.textValue);
					return false;
				});
			}
			div.append(shouyea).append(shangyiye);
			$.each(data.extend.pageInfo.navigatepageNums, function(i, item) {
				var a;
				if (item == data.extend.pageInfo.pageNum) {
					a = $('<span class="current"></span>').append(item);
				} else {
					a = $(' <a class="num" href=""></a>').append(item);
					a.click(function() {
						get_all_user_info(item, textName, textValue);
						return false;
					});
				}
				div.append(a);
			});

			//判断是否还有 下一页 
			var xiayiye;
			var moye;
			if (data.extend.pageInfo.hasNextPage) {
				xiayiye = $(' <a class="next" href="">&gt;&gt;</a>');
				moye = $('<a class="num" href="">末页</a>');
				xiayiye.click(function() {
					get_all_user_info(data.extend.pageInfo.pageNum + 1,
							textName.textValue);
					return false;
				});
				moye.click(function() {
					get_all_user_info(data.extend.pageInfo.pages, textName,
							textValue);
					return false;
				});
			} else {
				xiayiye = $(' <a class="next">&gt;&gt;</a>');
				moye = $('<a class="num">末页</a>');
			}
			div.append(xiayiye).append(moye);
			$('.page').append(div);
		}

		//查询按钮事件
		$('#select_btn').click(function() {
			var tUCount = $('#tUCount').val();
			if (tUCount == null || tUCount == '') {
				layer.msg('查询失败,请检查查询条件', {
					icon : 2,
					time : 1000
				//2秒关闭（如果不配置，默认是3秒）
				});
				return false;
			}
			if (tUCount != null && tUCount != '') {
				var textName = "tUCount";
				var textValue = tUCount;
				get_all_user_info(1, textName, textValue);
				return false;
			}
		});
		$('#not_audit').click(function(){
	    	var str = $('#not_audit').html();
	    	var textName = "tState";
			var textValue = str;
			get_all_user_info(1, textName, textValue);
			return false;
	    });
	    $('#audit').click(function(){
	    	var str = $('#audit').html();
	    	var textName = "tState";
			var textValue = str;
			get_all_user_info(1, textName, textValue);
			return false;
	    });
	    $('#success_audit').click(function(){
	    	var str = $('#success_audit').html();
	    	var textName = "tState";
			var textValue = str;
			get_all_user_info(1, textName, textValue);
			return false;
	    });
		/***
		获取url地址上参数
		 */
		function getUrlParam(url, name) {
			var pattern = new RegExp("[?&]" + name + "\=([^&]+)", "g");
			var matcher = pattern.exec(url);
			var items = null;
			if (matcher != null) {
				try {
					items = decodeURIComponent(decodeURIComponent(matcher[1]));
				} catch (e) {
					try {
						items = decodeURIComponent(matcher[1]);
					} catch (e) {
						items = matcher[1];
					}
				}
			}
			return items;
		}
	</script>

	<script>
		var _hmt = _hmt || [];
		(function() {
			var hm = document.createElement("script");
			hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
			var s = document.getElementsByTagName("script")[0];
			s.parentNode.insertBefore(hm, s);
		})();
	</script>
</body>
</html>